<template>
  <section>
    <el-table :data="goodsList">
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="state" label="状态" :formatter="stateFormatter"></el-table-column>
      <el-table-column prop="updated" label="时间" :formatter="timeFormatter"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="btnRegister(scope)">挂号</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="挂号订单" :visible.sync="showRegDialog">
      <showgoods :goods="currGoods" @cancel="cancelDialog" v-on:next="handleDialog" :v-on:cancel="cancelDialog"></showgoods>
    </el-dialog>
  </section>
</template>

<script>
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import DateFormat from '@/common/date-formater'
  import Showgoods from "./showgoods"
  export default {
    name: "createRegisterOrder",
    components: {Showgoods},
    data(){
      return {
        goodsList:null,
        showRegDialog:false,
        currGoods:{name:''},
      }
    },
    computed:{
      ...mapGetters(['department']),
    },
    created(){
      this.getGoodsList()
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      handleDialog(){
        console.log('————————————————————————————操作到这里')
      },
      timeFormatter(row, column, cellValue, index){
        console.log(cellValue)
        return DateFormat.formatDatetime(cellValue)
      },
      stateFormatter(row,column,cellValue,index){
        switch (cellValue) {
          case 0:return '待上架'
          case 1:return '上架'
          case 2:return '下架'
        }
      },
      getGoodsList() {
        this.fetch({name: "getGoodsList", data: {departmentId: this.department.id, page: 0, goodsTypeCode: 'register'}})
          .then(res => {
            console.log(res)
            this.goodsList = res.content
            //this.makeShowSkus()
          })
          .catch(err => {
            console.log(err)
            errHandler.handle(this, err)
          })
      },
      btnRegister(scope){
        this.currGoods = scope.row
        this.showRegDialog=true
      },
      cancelDialog(){
        this.showRegDialog=false
      }
    }
  }
</script>

<style scoped>

</style>
